$(function() {
	//表单验证
	$('#reg-box').validate({
		selectID: "#errortip" //指定弹出位置
	});
	let ti = 60,
		toggle = true;
	var app = new Vue({
		el: "#app",
		data: {
			Language: {},
			birthday: "2010-1-1",
			ms: {
				username: "",
				password: "",
				code: "",
				nickname: "",
				prefix: "60",
				language: "zh"
			},
		},
		methods: {
			Langes: function(v) {
				$.ajax({
					type: "get",
					dataType: "json",
					url: "../Langue/" + v + ".json",
					success: function(h) {
						app.Language = h;
					},
					error: function(e) {
						console.log("错误");
					}
				});
			},
			reg: function() {
				re_ajax(app.ms, "zh", function(h) {
					if(h.status) {
						$(window).attr("../login/login.html");
					} else {
						alert(h.msg);
					}
				})
			},
			cli: function() {
				if(toggle) {
					let dat = {};
					dat.prefix = app.ms.prefix;
					dat.username = app.ms.username;
					re_ajax("send_reg_code", dat, "zh", function(h) {
						if(!h.status) {
							alert(h.msg);
						} else {
							if(toggle) { //计时结束重新发送
								function show() { //开始计时的方法
									ti--;
									$("#send").text("(" + ti + ")s");
									if(ti == 0) {
										ti = 60;
										clearInterval(time);
										toggle = true;
										$("#send").text("发送短信");
									}
								}
							}
							var time = setInterval(show, 1000);
							toggle = false;
						}
					})
				}

			},
			sub_form: function() {
				if($('#reg-box').validate('submitValidate')) {
					re_ajax("put_member_reg", app.ms, "zh", function(h) {
						if(!h.status) {
							alert(h.msg);
						} else {
							alert("注册成功");
							$(window).attr("location", "login.html");
						}
					});
				}
			}
		}
	})
	//首次加载语言
	if(localStorage.getItem("lanuage")) {
		app.Langes(localStorage.getItem("lanuage"));
	} else {
		app.Langes("en");
	}
	window.app = app;
})